#ifndef __SEQLIST_H__
#define __SEQLIST_H__

#include <assert.h>

template<class DType>
struct SeqList {
	static const int defaultSize = 10;
	DType* elements;
	int capacity;
	int last;

	SeqList(int capacity = defaultSize) :elements(NULL), capacity(-1), last(-1) {
		if (capacity > 0) {
			this->capacity = capacity;
			last = -1;
			elements = new DType[capacity];
			for (int i = 0; i < capacity; i++)
				elements[i] = NULL;
		}
	}

	SeqList(const SeqList<DType>& other) {
		capacity = other.capacity;
		last = other.last;
		elements = NULL;
		if (other.elements) {
			elements = new DType[capacity];
			for (int i = 0; i < capacity; i++)
				elements[i] = other.elements[i];
		}
	}

	~SeqList() {
		if(elements)
			delete[]elements;
	}

	bool push(const DType& data);
	bool remove(int location);
	DType& operator[](int i);
	const DType& operator[](int i) const;

	int getLength() { return last+1; }
};

template<class DType>
bool SeqList<DType>::push(const DType& data) {
	if (last + 1 >= capacity) {
		return false;
	}
	elements[++last] = data;
	return true;
}

template<class DType>
bool SeqList<DType>::remove(int location) {
	if (location<0 || location>last) {
		return false;
	}
	for (int i = location; i < last; i++)
		elements[i] = elements[i + 1];
	last--;
	return true;
}

template<class DType>
DType& SeqList<DType>::operator[](int i) {
	assert(0 <= i && i <= last);
	return elements[i];
}

template<class DType>
const DType& SeqList<DType>::operator[](int i) const {
	assert(0 <= i && i <= last);
	return elements[i];
}

#endif //__SEQLIST_H__